package com.runa.rccprotocol.constant;

import com.runa.monitor.comm.entity.CommMeter;
import com.runa.persistence.CollectionUtil;
import com.runa.persistence.RepositoryServicePersis;
import com.runa.rccprotocol.em.ApportionCollectorModbusTypeEnum;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 2024/8/28 9:18
 * zhangYB
 */
public class ApportionCollector {


    private static Map<String, Map<String, String>> netEquMap = new ConcurrentHashMap<>();



    public static void putEquModel(String netEquNo, String equNo, String model) {
        Map<String, String> equMap = netEquMap.get(netEquNo);
        if (CollectionUtil.isEmpty(equMap)) {
            equMap = new ConcurrentHashMap<>();
            netEquMap.put(netEquNo, equMap);
        }
        if (!equMap.containsKey(equNo)) {
            equMap.put(equNo, model);
        }
    }

    public static String getEquModel(String netEquNo, String equNo) {
        Map<String, String> equMap = netEquMap.get(netEquNo);
        if (CollectionUtil.isNotEmpty(equMap)) {
            return equMap.get(equNo);
        }
        return null;
    }


    public static boolean isModbusType(String serial) {
        CommMeter commMeter = RepositoryServicePersis.getCommMeterBySerial(serial);
        if (null == commMeter) {
            return false;
        }
        return ApportionCollectorModbusTypeEnum.contains(commMeter.getModel());
    }



}
